﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.ExamItems;

namespace YaAppoint.Web.Controllers
{
    public class ExamItemController(IExamItemAppService examItemAppService) : AbpController
    {
        private readonly IExamItemAppService _examItemAppService = examItemAppService;

        [HttpGet("/api/exam-item/get-tree-data")]
        public async Task<IActionResult> GetLeftTreeData(Guid? depId)
        {
            return new JsonResult(await _examItemAppService.GetLeftTreeData(depId));
        }

        /// <summary>
        /// 检查项目同步
        /// 给定科室、给定设备类型下的检查项目同步
        /// </summary>
        [HttpGet("/api/exam-item/async")]
        public async Task<IActionResult> SyncData(Guid depId, Guid deviceTypeId)
        {
            return new JsonResult(await _examItemAppService.SyncData(depId, deviceTypeId));
        }

        /// <summary>
        /// 获取科室设备类型选项
        /// </summary>
        [HttpGet("/api/exam-item/get-dep-device-type-options")]
        public async Task<IActionResult> GetDepDeviceTypeOptions(Guid depId)
        {
            return new JsonResult(await _examItemAppService.GetDepDeviceTypeOptions(depId));
        }

        /// <summary>
        /// 获取适用性别选项
        /// </summary>
        [HttpGet("api/exam-item/get-applicable-sex-options")]
        public IActionResult GetApplicableSexOptions()
        {
            return new JsonResult(_examItemAppService.GetApplicableSexOptions());
        }


        /// <summary>
        /// 获取检查项目树形列表
        /// </summary>
        [HttpGet("/api/exam-item/get-exam-item-tree-list")]
        public async Task<IActionResult> GetExamItemTreeList(Guid depId, Guid deviceTypeId, string? filterName, int page, int pageSize)
        {
            return new JsonResult(await _examItemAppService.GetExamItemTreeList(depId,deviceTypeId,filterName,page,pageSize));
        }

        /// <summary>
        /// 提交新建
        /// </summary>
        [HttpPost("/api/exam-item/submit-create")]
        public async Task<IActionResult> SubmitCreate([FromBody] CreateExamItemDto dto, [FromQuery] Guid depId, [FromQuery] Guid deviceTypeId)
        {
            return new JsonResult(await _examItemAppService.SubmitCreate(dto,depId,deviceTypeId));
        }


        /// <summary>
        /// 删除多个
        /// </summary>
        [HttpPost("/api/exam-item/delete-many")]
        public async Task<IActionResult> DeleteMany([FromBody] List<Guid> idList)
        {
            return new JsonResult(await _examItemAppService.DeleteMany(idList));
        }

        /// <summary>
        /// 删除单个
        /// </summary>
        [HttpGet("/api/exam-item/delete")]
        public async Task<IActionResult> DeleteExamItem(Guid id)
        {
            return new JsonResult(await _examItemAppService.DeleteExamItem(id));
        }

        /// <summary>
        /// 获取检查项目详情
        /// </summary>
        [HttpGet("/api/exam-item/get")]
        public async Task<IActionResult> GetAsync(Guid id)
        {
            return new JsonResult(await _examItemAppService.GetAsync(id));
        }

        /// <summary>
        /// 编辑提交
        /// </summary>
        [HttpPost("/api/exam-item/submit-edit")]
        public async Task<IActionResult> SubmitEdit([FromBody] ExamItemDto dto)
        {
            return new JsonResult(await _examItemAppService.SubmitEdit(dto));
        }

        /// <summary>
        /// 获取文件夹树
        /// 带分页、每页数量切换
        /// </summary>
        [HttpGet("/api/exam-item/get-dir-tree")]
        public async Task<IActionResult> GetDirTree(Guid depId, Guid deviceTypeId, int page, int pageSize)
        {
            return new JsonResult(await _examItemAppService.GetDirTree(depId,deviceTypeId, page, pageSize));
        }

        /// <summary>
        /// 获取可检查设备选项
        /// </summary>
        [HttpGet("/api/exam-item/get-device-options")]
        public async Task<IActionResult> GetDeviceOptions(Guid examItemId)
        {
            return new JsonResult(await _examItemAppService.GetDeviceOptions(examItemId));
        }

        [HttpGet("/api/exam-item/get-device-options-by-devicetype")]
        public async Task<IActionResult> GetDeviceOptionsByDeviceType(Guid deviceTypeId)
        {
            return new JsonResult(await _examItemAppService.GetDeviceOptionsByDeviceType(deviceTypeId));
        }
    }
}
